﻿using System;
using CefSharp;

namespace BrowserHelper.CefSupport
{
    public class RpaDownloadHandler : IDownloadHandler
    {
        public void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem,
            IBeforeDownloadCallback callback)
        {
            if (!callback.IsDisposed)
            {
                using (callback)
                {
                    string path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                        downloadItem.SuggestedFileName);
                    callback.Continue(path, true);
                }
            }
        }

        public void OnDownloadUpdated(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem,
            IDownloadItemCallback callback)
        {
        }
    }
}